openreader: allow to disable fk contraint#431
Merged
Conversation
belopash
commented
Feb 10, 2026
| directive @fulltext(query: String!) on FIELD_DEFINITION | ||
| directive @cardinality(value: Int!) on OBJECT | FIELD_DEFINITION | ||
| directive @byteWeight(value: Float!) on FIELD_DEFINITION | ||
| directive @disableForeignKeyConstraint on FIELD_DEFINITION |
Contributor
Author
There was a problem hiding this comment.
@mo4islona not sure about directive name
There was a problem hiding this comment.
Pull request overview
Adds support in openreader/typeorm code generation to disable DB-level foreign key constraints for entity relationships, and updates the ERC20 transfers example to use nullable FK relations without enforced constraints.
Changes:
- Introduces
@disableForeignKeyConstraintdirective in openreader schema parsing and plumbs it through the model (FkPropType.disableConstraint). - Updates TypeORM model codegen to emit
createForeignKeyConstraints: falsefor FK relations when requested. - Extends OpenCRUD schema/query planning to expose
<fkField>Idscalar fields and allow selecting/filtering by them; updates theerc20-transfersexample schema/models/migrations accordingly.
Reviewed changes
Copilot reviewed 11 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| typeorm/typeorm-codegen/src/codegen.ts | Emits createForeignKeyConstraints: false for FK relations when disableConstraint is set. |
| graphql/openreader/src/model.ts | Adds disableConstraint?: boolean to FkPropType. |
| graphql/openreader/src/model.schema.ts | Adds @disableForeignKeyConstraint directive and maps it into FK property metadata. |
| graphql/openreader/src/util/util.ts | Adds helpers to derive/recognize <fkField>Id virtual fields. |
| graphql/openreader/src/sql/cursor.ts | Allows resolving virtual <fkField>Id fields as scalar columns. |
| graphql/openreader/src/dialect/opencrud/schema.ts | Exposes <fkField>Id output fields and adds where-filter support for them. |
| graphql/openreader/src/dialect/opencrud/tree.ts | Allows requesting <fkField>Id even though it isn’t a modeled property. |
| test/erc20-transfers/schema.graphql | Adds Account entity and marks Transfer.from/to with @disableForeignKeyConstraint. |
| test/erc20-transfers/src/model/generated/account.model.ts | Adds generated Account entity model. |
| test/erc20-transfers/src/model/generated/transfer.model.ts | Changes from/to from scalar strings to FK relations with constraints disabled. |
| test/erc20-transfers/src/model/generated/index.ts | Exports the newly generated Account model. |
| test/erc20-transfers/src/processor.ts | Writes from/to as Account references (id-only objects) instead of strings. |
| test/erc20-transfers/db/migrations/1770630835290-Data.js | New migration reflecting the new schema (account table + transfer FK id columns + indexes). |
| test/erc20-transfers/db/migrations/1682961487386-Data.js | Removes the old migration that stored from/to as text columns. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.